package cn.com.generaldata.os.ws.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.generaldata.jsme_indicator_system.entity.AreaPerformNz;
import cn.com.generaldata.jsme_indicator_system.entity.BiIndicatorNz;
import cn.com.generaldata.jsme_indicator_system.entity.IndicatorInfo;
import cn.com.generaldata.os.newpojo.SystemCodedic;
import cn.com.generaldata.os.service.impl.IndicatorGisService;
import cn.com.generaldata.os.vo.GISCoordinate;
import cn.com.generaldata.os.vo.GisShowDataVO;
import cn.com.generaldata.os.vo.IndicatorCategoryVO;
import cn.com.generaldata.os.vo.IndicatorQueryVO;
import cn.com.generaldata.os.vo.ReportIndicatorQueryVO;
import cn.com.generaldata.os.ws.intf.IndicatorGisWSInterface;

public class IndicatorGisWS implements IndicatorGisWSInterface {

	private static Logger logger = LoggerFactory.getLogger(IndicatorGisWS.class);

	private IndicatorGisService indicatorGisService;

	public void setIndicatorGisService(IndicatorGisService indicatorGisService) {
		this.indicatorGisService = indicatorGisService;
	}

	/**
	 * 查询全部指标信息
	 */
	@Override
	public List<IndicatorInfo> queryIndicatorVO() {
		return indicatorGisService.queryIndicatorVO();
	}

	/**
	 * 查询全部区划
	 */
	@Override
	public List<AreaPerformNz> queryAreaVO(String areaId) {
		return indicatorGisService.queryAreaVO(areaId);
	}

	/**
	 * 查询指标信息
	 */
	@Override
	public List<IndicatorQueryVO> queryReportIndicator(ReportIndicatorQueryVO queryVO) {
		List<IndicatorQueryVO> volist = new ArrayList<IndicatorQueryVO>();
		try {
			volist = indicatorGisService.queryIndicators(queryVO);

			return volist;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			//			result.setDefaultError();
			return volist;
		}
	}

	/**
	 * 外部查询指标
	 */
	@Override
	public List<BiIndicatorNz> queryBiIndicator() {
		return indicatorGisService.queryBiIndicator();
	}

	/**
	 * 外部查询指标值
	 */
	@Override
	public List<GisShowDataVO> queryGisIndicator(String indicatorIds, String areaIds, String startDate, String endDate,
			String areatype) {
		return indicatorGisService.queryGisIndicator(indicatorIds, areaIds, startDate, endDate, areatype);
	}

	/**
	 * 查询所有分类
	 */
	@Override
	public List<IndicatorCategoryVO> queryCategory() {
		return indicatorGisService.queryCategory();
	}

	/**
	 * 查询分类下以保存的指标
	 */
	@Override
	public List<BiIndicatorNz> queryByCategory(String name) {
		return indicatorGisService.queryByCategory(name);
	}

	/**
	 * 调整保存的指标
	 */
	@Override
	public void updateBiIndicator(String ids) {
		indicatorGisService.updateBiIndicator(ids);
	}

	/**
	 * 查询用海企业的指标
	 */
	@Override
	public String queryReportData(String unitName, String reportName, String year) {
		List<Map<String, String>> queryReportData = indicatorGisService.queryReportData(unitName, reportName, year);
		String json = Json.toJson(queryReportData, JsonFormat.compact());
		return json;
	}

	/**
	 * 查询用海企业基本信息
	 */
	@Override
	public String queryUnits(String unitName, String year) {
		// TODO Auto-generated method stub
		List<Map<String, String>> queryReportData = indicatorGisService.queryReportData(unitName, "用海企业基本情况", year);
		String json = Json.toJson(queryReportData, JsonFormat.compact());
		return json;
	}

	/**
	 * 查询用海企业坐标
	 */
	@Override
	public List<GISCoordinate> queryUnitsArea(String unitName, String year) {
		// TODO Auto-generated method stub
		List<Map<String, String>> queryReportData = indicatorGisService
				.queryReportData(unitName, "海域使用权证号及界址点坐标", year);
		List<GISCoordinate> turnGisCoordinate = indicatorGisService.turnGisCoordinate(queryReportData);
		List<GISCoordinate> coordinate = indicatorGisService.arrangeCoordinate(turnGisCoordinate);
		return coordinate;
	}

	/**
	 * 查询用海报表
	 */
	@Override
	public List<String> queryReportType(String year) {
		List<String> queryReportData = indicatorGisService.queryReporType(year);
		return queryReportData;
	}

	@Override
	public List<SystemCodedic> queryType() {
		// TODO Auto-generated method stub
		return null;
	}
}
